.LemonModal__overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    transition:
        background-color var(--modal-transition-time) ease-out,
        backdrop-filter var(--modal-transition-time) ease-out;

    &.LemonModal__overlay--force-modal-above-popovers {
        z-index: var(--z-force-modal-above-popovers);
    }

    &.ReactModal__Overlay--after-open {
        background-color: var(--modal-backdrop-color);
        backdrop-filter: blur(var(--modal-backdrop-blur));
    }

    &.ReactModal__Overlay--before-close {
        background-color: transparent;
        backdrop-filter: blur(0);
    }

    @each $i in (1161, 1162, 1166, 1167, 1168, 1169) {
        &.LemonModal__overlay--z-#{$i} {
            z-index: #{$i};
        }
    }
}

.LemonModal {
    position: relative;
    display: flex;
    flex-direction: column;
    width: fit-content;
    min-width: min(28rem, 100%);
    max-width: 90%;

    // Always give toasts some space at the bottom
    max-height: calc(100vh - 60px - 2rem);
    margin: 1rem auto;
    background-color: var(--color-bg-surface-primary);
    border: 1px solid var(--border-bold);
    border-radius: var(--radius);
    box-shadow: var(--modal-shadow-elevation);
    opacity: 0;
    transition:
        opacity var(--modal-transition-time) ease-out,
        transform var(--modal-transition-time) ease-out;
    transform: scale(0.85);

    // Transition properties
    will-change: transform;

    &.LemonModal--fullscreen {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        margin: 0;
        border: none;
        border-radius: 0;
    }

    &.ReactModal__Content--after-open:not(.ReactModal__Content--before-close) {
        opacity: 1;
        transform: scale(1);
    }

    .LemonModal__close {
        position: absolute;
        top: 0.75rem;
        right: 1rem;
        z-index: 1;

        &.LemonModal__close--highlighted {
            animation: LemonModal__tilt-shake 400ms;
        }
    }

    // We nest the content in layout so that "simple" modal implementations can use this class as well
    .LemonModal__layout {
        display: flex;
        flex: 1;
        flex-direction: column;
        overflow-y: hidden;
    }

    .LemonModal__content {
        padding: 1rem;
        overflow-y: auto;

        &.LemonModal__content--embedded {
            padding: 0;
        }
    }

    .LemonModal__container {
        display: flex;
        height: 100%;
        overflow: hidden;
    }
}

.LemonModal__header {
    padding-bottom: 1rem;
    margin: 1rem;
    margin-bottom: 0;
    border-bottom: 1px solid var(--color-border-primary);

    h3 {
        margin-right: 2.5rem;
        margin-bottom: 0;
        font-size: 1.125rem;
        font-weight: 700;
        line-height: 1.5rem;
    }

    p {
        margin: 0.5rem 0 -0.25rem;
    }
}

.LemonModal__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    padding-top: 1rem;
    margin: 1rem;
    margin-top: 0;
    white-space: nowrap;
    border-top: 1px solid var(--color-border-primary);
}

.LemonModal__header + .LemonModal__footer {
    border-top: none;
}

@keyframes LemonModal__tilt-shake {
    0% {
        transform: rotate(0deg);
    }

    16.666% {
        transform: rotate(12deg);
    }

    50% {
        transform: rotate(-10deg);
    }

    83.333% {
        transform: rotate(8deg);
    }

    100% {
        transform: rotate(0deg);
    }
}
